package net.butfly.bus;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import net.butfly.bus.context.Constants;
import net.butfly.bus.exception.BusRuntimeException;

public class Request implements Serializable {
	private static final long serialVersionUID = -3216119686409193334L;
	private String tx;
	private String version = "1.0";
	private String user;
	private String password;
	// TODO
	// private String clientip;
	private String currentFlowNo;
	private String currentNodeId;
	private Object[] args;

	private Map<String, Object> extParamMap;

	public Request() {
		args = new Object[] {};
		extParamMap = new HashMap<String, Object>();
	}

	public String getTx() {
		return tx;
	}

	public void setTx(String tx) {
		this.tx = tx;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Object[] getArgs() {
		return args;
	}

	public void setArgs(Object[] args) {
		this.args = args;
	}

	public Object getAttritube(String attrName) {
		return attrName == null || "".equals(attrName) || extParamMap == null ? null : extParamMap.get(attrName);
	}

	public void putAttribute(String attrName, Object attrValue) {
		if (attrName == null || "".equals(attrName)) {
			throw new BusRuntimeException(Constants.UserError.BAD_REQUEST, "设置Attribute的Key不能为null");
		}
		extParamMap.put(attrName, attrValue);
	}

	public void addContext(Map<String, Object> map) {
		extParamMap.putAll(map);
	}

	public Map<String, Object> getContext() {
		return extParamMap;
	}

	public String getCurrentNodeId() {
		return currentNodeId;
	}

	public void setCurrentNodeId(String currentNodeId) {
		this.currentNodeId = currentNodeId;
	}

	public String getCurrentFlowNo() {
		return currentFlowNo;
	}

	public void setCurrentFlowNo(String currentFlowNo) {
		this.currentFlowNo = currentFlowNo;
	}
}
